package org.shopping.web.commodity;

import org.shopping.domain.Commodity;
import org.shopping.domain.PageBean;
import org.shopping.service.commodity.CommodityService;
import org.shopping.service.commodity.impl.CommodityServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "FindPageCommodityController", value = "/FindPageCommodityController")
public class FindPageCommodityController extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.获取页面提交的页码数
        String strPage = request.getParameter("currentPage");
        //2.创建业务层对象,调用分页查询方法
        CommodityService service = new CommodityServiceImpl();
        PageBean<Commodity> pageBean = service.findPageByCurrentPage(
                Integer.parseInt(strPage),9);
        //3.保存到域对象,转发到分页页面显示
        request.setAttribute("pageBean",pageBean);
        request.getRequestDispatcher("/index.jsp").forward(request,response);
    }
}
